#include <omp.h> 
#include <stdio.h>
static long num_steps = 100000; 
double step; 
#define NUM_THREADS 4 
void main () {
    double pi, sum[NUM_THREADS]; //不再需要数组 
    step = 1.0/(double) num_steps;
    omp_set_num_threads(NUM_THREADS); 
    #pragma omp parallel 
    {
    double x,sum; //增加一个每个线程都有的加和变量 
    int id; 
    id = omp_get_thread_num(); 
    for (int i=id; i< num_steps; i=i+NUM_THREADS){ 
        x = (i+0.5)*step; 
        sum += 4.0/(1.0+x*x); //不再需要对数组操作
    }
        #pragma omp atomic 
        pi+=sum*step;
    }
    printf("pi = %.20lf\n", pi);
}